home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
-
- char *strsep (char **stringp, char *delim)
- {
- char *save_string, *brk;
-
- if ((save_string = *stringp) == NULL)
- return (NULL);
-
- if (brk = strpbrk (*stringp, delim))
- {
- *brk = '\0';
-
- *stringp = brk + 1;
-
- }
- else
- {
- *stringp = NULL;
- }
-
- return (save_string);
- }
-
-
- #ifdef TEST
-
- #include <stdio.h>
-
- main()
- {
- char *string = "one two three four five";
-
- while (string)
- {
- char *token;
-
- while ((token = strsep (&string, " ")) && (*token == '\0')) ;
-
- printf ("%s\n", token);
- }
- }
-
- #endif
-